package com.dong.view;

import com.dong.yi18health.DetailActivity;
import com.dong.yi18health.R;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

public class MyListView extends ListView {

	private int downx;
	private int downy;
	private int id;

	public MyListView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	
	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		int action = ev.getAction();
		
		switch (action) {
		
		case MotionEvent.ACTION_DOWN:
			downx = (int) ev.getX();
			downy = (int) ev.getY();
			
			int index = this.pointToPosition(downx, downy);
			System.out.println("--MyListView的index"+index);
			View view = this.getChildAt(index);
			if(view!=null){
				TextView tid = (TextView) view.findViewById(R.id.item1_id);
				String string = tid.getText().toString();
				id = Integer.parseInt(string);
				view.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View arg0) {
						Intent it=new Intent(getContext(), DetailActivity.class);
						it.putExtra("id", id);
						System.out.println("---传递过去的id"+id);
						getContext().startActivity(it);
					}
				});
			}
			break;
		}
		super.onTouchEvent(ev);
		return true;
	}
	
}
